package aex.service;



import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import aex.dao.ShowPointDao;
import aex.domain.ShowPoint;
import aex.util.PageBean;



@Transactional(readOnly = false)
@Service(ShowPointService.SERVICE_NAME)

public class ShowPointService {

	
	public static final String SERVICE_NAME="aex.service.ShowPointService";
	/**
	 * 以注解的形式让spring为我们注入dao的实现类
	 */
	@Resource(name = ShowPointDao.SERVICE_NAME)
	public ShowPointDao dao;
	
	
	@Resource(name = ShowBoxService.SERVICE_NAME)
	public ShowBoxService sbService;
	
	public ShowPointService() {
	}

	
	/**
	 * 通过id查询一个展位
	 * @param i
	 * @return
	 */
	
	public ShowPoint findByID(Serializable id) {
		return dao.findObjectByID(Integer.parseInt(id+""));
	}
	
	
	/** 展位 保存
	 * @param obj
	 */
	public void save(ShowPoint obj){
		dao.save(obj);
	}


	/**
	 * 通过对象的id找到对应的展位
	 * @param id
	 * @return
	 */
	public List<ShowPoint> findPointByTargetId(Serializable id) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.spOrderBy", "desc");
		return dao.findCollectionByConditionNoPage("and tName.spTargetId="+Integer.parseInt(id+""), null, orderby);
	}


	/**
	 * 通过对应对象的id删除对应的展位
	 * @param id
	 */
	public void delPointByTargetId(Serializable id) {
		dao.deleteObjectByCollection(findPointByTargetId(id));
	}

	
	public void deleteById(Serializable id) {
		// TODO Auto-generated method stub
		
	}
	
	public void update(ShowPoint obj) {
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * 安装展柜名称查找展位
	 * 且带分页
	 * @param string
	 * @param pageBean
	 * @return
	 */
	public PageBean<ShowPoint> findPointByName(String showBoxName , PageBean<ShowPoint> pageBean) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.spOrderBy", "desc");
		return dao.findPageBean("and tName.showBox="+sbService.findBoxByName(showBoxName).getSbId(), null, orderby, pageBean);
	}
	
	
	

}
